<?php
namespace App\Common\Lib\Swoole;

use App\Common as com;

class Coroutine extends com\Lib\LibBase {

	/**
	 * 睡眠(相对时间)
	 * @param float $seconds 睡眠时间
	 * @param int $lastTimeMs 最后sleep完成时间
	 * @return int
	 */
	public static function relativelySleep( float $seconds, int $lastTimeMs ):int {
		$realSeconds = $seconds * 1000;
		if( $lastTimeMs > 0 ){
			$realSeconds = $realSeconds - ( com\Lib\Fun\Time::getTimeOfMillitime() - $lastTimeMs );
		}
		$realSeconds = $realSeconds / 1000;
		//
		if( $realSeconds > 0 ){
			\Swoole\Coroutine::sleep( $realSeconds );
		}
		//
		return com\Lib\Fun\Time::getTimeOfMillitime();
	}

}
